#pragma once

// Connection to windows frame work
// Initialize data structure and view class.
// Pass all application messages to game logics

#include "Model.h"
#include "View.h"

class Application
{
public:
	Application(void);
	~Application(void);

	int Start( HINSTANCE hInstance , TCHAR * szTitle , TCHAR * szWindowClass , float fWidth , float fHeight , int nCmdShow );
	void Destory();
	void MessageLoop();

	// Get functions 

	// For windows platform
	HINSTANCE	GetINSTANCE	() const;
	HWND		GetHWND		() const;
	inline float	GetWidth	() const { return this->mfWidth; }
	inline float	GetHeight	() const { return this->mfHeight; }

protected:
	static Application * sSingleInstance;
	static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

	virtual bool onInit() = 0; // for init model and view.
	virtual void onIdle();
	
	void setModel( Model * inModel );
	void setView( View * inView );

	inline Model	* getModel() { return this->mpModel; }
	inline View		* getView() { return this->mpView; }

private:
	Model	* mpModel	;
	View	* mpView	;

	float	mfWidth		;
	float	mfHeight	;

	// for Windows
	HINSTANCE	mhInstance	;
	HWND		mhWnd		;
	DWORD		muLastTick	;

	ATOM _myRegisterClass( HINSTANCE hInstance , TCHAR * szWindowClass );
	BOOL _initInstance( HINSTANCE hInstance , TCHAR * szTitle , TCHAR * szWindowClass , int nCmdShow );
	bool MessageProc( UINT message, WPARAM wParam, LPARAM lParam );
};

